<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>javascript</title>
  <link rel="stylesheet" href="my.css" >
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box
    }
    body {
      font-size: 14px;
      padding: 20px;
    }
    ul li {
      line-height: 30px;
    }
  </style>
</head>
<body>
  <input type="text" id="text"  value="" />
  <div id="app"></div>
</body>
<script>
  var obj = {
    txt: ''
  }
  var val = obj.txt
  Object.defineProperty(obj, 'txt', {
    get: function() {
      return val
    },
    set: function(newV) {
      val = newV
      document.querySelector("#app").innerHTML = newV
    }
  })
  document.querySelector("#text").addEventListener('keyup', function(e) {
    obj.txt = e.target.value 
  })
  console.log(obj.txt)
</script>
</html>